package Exercise;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author 王艺锡
 * @version 1.0
 */
public class Exercise01 {
    public static void main(String[] args) throws IOException {
        String directorPath = "e:\\mytemp";
        File file = new File(directorPath);
        if(file.exists()){
            System.out.println("目录已存在");
        }else {
            if(file.mkdir()){//mkdir创建一级目录
                System.out.println("创建成功");
            }else {
                System.out.println("创建失败");
            }
        }

        String filePath = "e:\\mytemp\\hello.txt";
        file = new File(filePath);
        if(file.exists()){
            System.out.println("文件已存在");
        }else {
            if(file.createNewFile()){
                BufferedWriter bw = new BufferedWriter(new FileWriter(filePath));
                bw.write("hello,world");
                bw.close();
                System.out.println("创建文件成功");
            }else {
                System.out.println("创建文件失败");
            }
        }

    }
}
